/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


myApp.controller('postOrderController',
        //['$scope'],
        function($scope, $location, postOrders, $route, $cookies,$rootScope) {
    $rootScope.showSearchBar = true;
    $rootScope.showWelcomeMessage = true;
    $rootScope.isLoginPage = true;
    var postMealSuccess = function() {
        alert("Order Posted");
        $rootScope.showAlert("Your order has been posted.");
        $cookies.mealOrders = JSON.stringify([]);
        //$route.reload();
    }
    var postMealFailure = function() {
        console.log("Failure while posting meal.");
    }
    
    $scope.postData = function(){
        var orders;
        try{
            orders = JSON.parse($cookies.mealOrders);
        }
        catch(err){
            orders = [];
        }
        postOrders.postOrders(orders).then(postMealSuccess, postMealFailure);
    };
    
});